package com.servlet;

import com.alibaba.fastjson.JSONObject;
import com.pojo.Layui;
import com.pojo.User;
import com.service.apply.ApplyServiceImpl;
import com.util.Constant;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class ApplyUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        Object o = req.getSession().getAttribute(Constant.USER_SESSION);
        int userId = ((User)o).getUserId();
        ApplyServiceImpl applyService = new ApplyServiceImpl();
        List<Object> applys = applyService.getUserApplyList(userId);
        Layui layui = new Layui();
        layui.setCode(0);
        layui.setCount(1000);
        layui.setMsg("");
        layui.setData(applys);
        resp.getWriter().write(JSONObject.toJSONString(layui));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
